import inspect
import os
from functools import reduce


class Common:

    def __init__(self):
        pass

    @staticmethod
    def _get_current_path():
        """私有函数
        获取当前文件路径(注意路径包含当前文件名)
        :return: str
        """
        try:
            filename = __file__
        except NameError:  # fallback
            filename = inspect.getsourcefile(Common._get_current_path)
        return os.path.realpath(filename)

    # 返回上n级
    @staticmethod
    def _get_dir(n=1):
        """私有函数
        获取上n级的路径
        :param n: n级路径
        :return: 上n级的路径
        """
        cm_path = Common._get_current_path()
        return reduce(lambda x, f: f(x), [os.path.dirname] * n, cm_path)

    @staticmethod
    def get_root_path():
        """获取根路径
        :return: str
        """
        return Common._get_dir(n=1)
